package com.smartshopping.iu;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

public class ListNewsActivity extends Activity {

	private String url = "";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list_news);
		createButton();
	}

	public void createButton()
	{
		TextView imageView_1 = (TextView)findViewById(R.id.list_news_textview_1);
		TextView imageView_2 = (TextView)findViewById(R.id.list_news_textview_2);
		TextView imageView_3 = (TextView)findViewById(R.id.list_news_textview_3);
		TextView imageView_4 = (TextView)findViewById(R.id.list_news_textview_4);
		TextView imageView_5 = (TextView)findViewById(R.id.list_news_textview_5);
				
		setOnClick(imageView_1);
		setOnClick(imageView_2);
		setOnClick(imageView_3);
		setOnClick(imageView_4);
		setOnClick(imageView_5);
	}
	
//  Set the handler of each imageButton	OnClick
	public void setOnClick(TextView textView) {
		textView.setOnClickListener(new OnClickListener() {
	        @Override
	        public void onClick(View v) {
	        	// Kiem tra ID cua button goi layout phu hop
	        	switch(v.getId()) { 
			    	case R.id.list_news_textview_1:   
			    		url = "http://www.coopmart.vn/khuyenmai/sanphamkhuyenmai.aspx";
			    		Intent myIntent1 = new Intent(ListNewsActivity.this, NewsActivity.class);
			        	myIntent1.putExtra("url", url);
				    	ListNewsActivity.this.startActivity(myIntent1);
			    	break;
			    		 
			    	case R.id.list_news_textview_2:
			    		url = "http://bigc.vn/Install/UnderConstruction.htm";
			    		Intent myIntent2 = new Intent(ListNewsActivity.this, NewsActivity.class);
			        	myIntent2.putExtra("url", url);
				    	ListNewsActivity.this.startActivity(myIntent2);
			    	break;
			    	
			    	case R.id.list_news_textview_3:
			    		url = "http://www.lottemart.com.vn/";
			    		Intent myIntent3 = new Intent(ListNewsActivity.this, NewsActivity.class);
			        	myIntent3.putExtra("url", url);
				    	ListNewsActivity.this.startActivity(myIntent3);
			    	break;
			    	
			    	case R.id.list_news_textview_4:
			    		url = "http://satra.com.vn/index.php/vn/tin-tuc/tin-satra/";
			    		Intent myIntent4 = new Intent(ListNewsActivity.this, NewsActivity.class);
			        	myIntent4.putExtra("url", url);
				    	ListNewsActivity.this.startActivity(myIntent4);
			    	break;
			    	
			    	case R.id.list_news_textview_5:
			    		url = "http://www.maximark.com.vn/index.php?act=promo";
			    		Intent myIntent5 = new Intent(ListNewsActivity.this, NewsActivity.class);
			        	myIntent5.putExtra("url", url);
				    	ListNewsActivity.this.startActivity(myIntent5);
			    	break;
	        	} 
	        	
	        }
	    });
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.list_news, menu);
		return true;
	}

}
